// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import VueRouter from 'vue-router'
import FastClick from 'fastclick'
import routes from './router/router'
import { LoadingPlugin, ToastPlugin } from 'vux'
import App from './App'
import { routerMode } from '../config/env'

Vue.use(VueRouter)
Vue.use(LoadingPlugin)
Vue.use(ToastPlugin)
FastClick.attach(document.body)

Vue.config.productionTip = false

const router = new VueRouter({
  routes,
  mode: routerMode,
  strict: process.env.NODE_ENV !== 'production',
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.body.scrollTop
      }
      return { x: 0, y: to.meta.savedPosition || 0 }
    }
  }
})

/*
 *  设置页面title信息
 */
Vue.directive('title', {
  inserted: function (el, binding) {
    document.title = el.innerText
    el.remove()
  }
})

/* eslint-disable no-new */
new Vue({
  router
}).$mount('#app')
